<?php

function lib_get_topic_type_option(){
	db_charset();
	$res = db_get('topic_type','*','WHERE topic_type_is_show=1 ORDER BY topic_type_order DESC');
	$return_str='';
	while ($row = mysql_fetch_assoc($res)) {
		$return_str.='<option value="'.$row['topic_type_tid'].'">'.$row['topic_type_name'].'</option>';
	}
	return $return_str;	
	
}

function lib_get_topic_type_arr(){
	db_charset();
	$res = db_get('topic_type','*','WHERE topic_type_is_show=1 ORDER BY topic_type_order DESC');
	$a=array();
	while ($row = mysql_fetch_assoc($res)) {
		$a[]=$row;
	}
	return $a;	
	
}

function lib_get_friend_link_arr(){
	db_charset();
	$res = db_get('friend_link','*','WHERE friend_link_is_show=1 ORDER BY friend_link_order DESC');
	$a=array();
	while ($row = mysql_fetch_assoc($res)) {
		$a[]=$row;
	}
	
	return $a;
	
}

function lib_get_reply($tid){
	
	$res = db_get('reply','*',"WHERE reply_topic_tid='{$tid}' ORDER BY reply_birthday DESC");
	return db_fetch($res);
	
	
}

/**
 * 得到指定文章的TAG的ARR
 *
 * @param unknown_type $t_id
 * @return unknown
 */
function lib_get_topic_tag_arr($t_id){
	db_charset();
	$t_id = mysql_escape_string($t_id);
	$res = db_get('topic_tag','*'," WHERE topic_tid='{$t_id}'");
	return db_fetch($res);
}

/**
 * 得到指定文章的TAG的文字
 *
 * @param unknown_type $t_id
 * @param unknown_type $delimiter
 * @return unknown
 */
function lib_get_topic_tag_text($t_id,$delimiter=','){
	db_charset();
	$t_id = mysql_escape_string($t_id);
	$res = db_get('topic_tag','*'," WHERE topic_tid='{$t_id}'");
	
	$return_text = '';
	while ($row = mysql_fetch_assoc($res)) {
		$return_text .= $row['topic_tag_words'].$delimiter;
	}
	$return_text = trim($return_text,',');

	return $return_text;
}


/**
 * 
 * 把TAG值写为持久变量
 * 
 * 
 *
 * @param unknown_type $limit_s
 * @param unknown_type $limit_e
 */

function lib_topic_tag_build_refresh($limit_s = 0,$limit_e = 20){

	db_charset();
	
	$sql = "SELECT * FROM (SELECT *,COUNT(*) AS count FROM topic_tag GROUP BY topic_tag_words) AS tag ORDER BY tag.count DESC LIMIT {$limit_s},{$limit_e} ";
	
	$res = db_query($sql);
	
	$array = db_fetch($res);

	$GLOBALS['LVAR']->topic_tag=$array;
	
	
}
/**
 * 得到所有TAG
 * 
 *
 * @param unknown_type $limit
 * @return unknown
 */
function lib_topic_tag_get_all(){
	
	return $GLOBALS['LVAR']->topic_tag;
	
}


?>